<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = & get_instance();
	if(!isUserLogin()){
		redirect(site_url());exit();
	}
	$USER = $ci->user_entity->init('id', getUserId());
	$listPackages = $ci->coin_packages_entity->getCoinPackagesType('offline');
	$offlinePaymentArray = offlinePaymentTypeDataConfig();
?>

<style>
	.datetimeip{float:left; margin-left: 5px;margin-top:5px;width:113px;height:20px;background:#eeeeee;border:1px solid #cfcfcf;position:relative;display:block;}
	.datetimeip input.dateip{float:left;width:90px;height:13px;margin-left:5px;margin-top:5px; background:none repeat scroll 0 50% transparent;border:0 none;color: #000000; font-size: 12px;}
	.datetimeip input.buttonicon{float:left;width:20px;height:20px;margin: 6px 0 0 7px;margin: 6px 0 0 4px\9;border:0 none;cursor: pointer;}
	.datetimebt{float:left;width:50px;height:23px;font-size: 12px;background:#006699;border:1px solid #b1c0cb;display:block;text-align:center;font-weight:bold;cursor:pointer;color:#FFF;margin-left:30px;}
	.ui-datepicker-trigger{margin-top:2px;cursor:pointer;}
</style>

<form action="<?php echo site_url('cricket/account/add_coin_offline');?>" name="add_coin_offline" id="add_coin_offline" method="post" enctype="multipart/form-data" >
<div id="center_content">
	<div class="clrboth"></div>
	<div class="block">
		<div class="title" style="position:relative;">
			<h3 class="bold"><a href="<?php echo site_url("cricket/user/dashboard")?>">Dashboard</a> &raquo; Add CX coins</h3>
			<a class="back_button2" href="<?php echo site_url("cricket/user/dashboard")?>" title="Back?">Back?</a>	
		</div>
		<div class="clrboth"></div>
		<div class="content">
			<div class="rowitem3">
				<div class="clrboth"></div>
					<?php $this->load->view('cricket/user/payment_modes'); ?>
				<div class="clrboth"></div>	
				<br/>
				1. Choose a Package
				<div class="clrboth"></div>	
				
				<table class="summary">
					<thead>
						<td width="10%">Select</td>
						<td width="40%">Package</td>
						<td width="25%">Amount (INR)</td>
						<td width="25%">Coin</td>
					</thead>
					<tbody>
						<?php foreach($listPackages as $item): ?>
							<?php $PACKAGE = $ci->coin_packages_entity->init('id', $item->id); ?>
							<tr>
								<td><input type="radio" name="package" value="<?php echo $PACKAGE->getId();?>" style="cursor:pointer;" /></td>
								<td><?php echo $PACKAGE->getPackage();?></td>
								<td style="text-align:right;"><?php echo format_Money($PACKAGE->getCost(),true);?>&nbsp;</td>
								<td style="text-align:right;"><?php echo $PACKAGE->getCoin();?>&nbsp;</td>
							</tr>
						<?php endforeach;?>
					</tbody>
				</table>
				<div class="clrboth"></div>
				
				<br/>
				2. Payment Options 
				<div class="clrboth"></div>
				<br/>
				<div class="clrboth"></div>
				{pyro:getpost:body id="1"}
				<div class="clrboth"></div>
				<br/>
				
				3. Submit Payment Details
				<div class="clrboth"></div>
				<br />
				
				<div class="grid2"><span class="bold">*Offline pay via:</span></div>
				<div class="grid6"><?php echo form_dropdown( 'type',
											$options = offlinePaymentTypeDataConfig(),
											$selected = array(),
											"id='type' style='margin:5px;width:255px;' onchange='return changeStateOfSelectedbox();'"
										);	?></div> 
				<div class="clrboth"></div>
				
				<div id="bank_deposit" class="hidden">
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Bank name:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="bank_name" name="bank_name" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="bank_name_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Bank branch:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="bank_branch" name="bank_branch" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="bank_branch_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Deposited date:</span></div>
					<div class="grid6">
						<div class="datetimeip">
							<input type="text" class="dateip" id="deposited_date" name="deposited_date" />
						</div>
					</div>
					<div class="grid2"><span class="bold red hidden" id="deposited_date_error">Required field.</span></div>
					<div class="clrboth"></div>	
				</div>
				<div class="clrboth"></div>
				
				<div id="neft_transfer" class="hidden">
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Remitter's A/C Name:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="remitter_ac_name" name="remitter_ac_name" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="remitter_ac_name_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Remitter's A/C Number:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="remitter_ac_number" name="remitter_ac_number" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="remitter_ac_number_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Remitter's Bank Name:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="remitter_bank_name" name="remitter_bank_name" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="remitter_bank_name_error">Required field.</span></div>
					<div class="clrboth"></div>	
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Transfer Date:</span></div>
					<div class="grid6">
						<div class="datetimeip">
							<input type="text" class="dateip" id="transfer_date" name="transfer_date" />
						</div>
					</div>
					<div class="grid2"><span class="bold red hidden" id="transfer_date_error">Required field.</span></div>
					<div class="clrboth"></div>	
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Transfer Time:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="transfer_time" name="transfer_time" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="transfer_time_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Transaction Id:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="transaction_id" name="transaction_id" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="transaction_id_error">Required field.</span></div>
					<div class="clrboth"></div>
					
				</div>
				<div class="clrboth"></div>
				
				<div id="dd" class="hidden">
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*DD No.:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="dd_no" name="dd_no" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="dd_no_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Bank name:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="dd_bank_name" name="dd_bank_name" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="dd_bank_name_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Remitter's address:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="remitter_address" name="remitter_address" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="remitter_address_error">Required field.</span></div>
					<div class="clrboth"></div>	
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*DD Date:</span></div>
					<div class="grid6">
						<div class="datetimeip">
							<input type="text" class="dateip" id="dd_date" name="dd_date" />
						</div>
					</div>	
					<div class="grid2"><span class="bold red hidden" id="dd_date_error">Required field.</span></div>
					<div class="clrboth"></div>
				</div>
				<div class="clrboth"></div>
				
				<div id="emoney_order" class="hidden">
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*e-Money Order No.:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="emoney_order_no" name="emoney_order_no" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="emoney_order_no_error">Required field.</span></div>
					<div class="clrboth"></div>
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*Remitter's address:</span></div>
					<div class="grid6"><input type="text" maxlength="45" id="emoney_remitter_address" name="emoney_remitter_address" class="std-input"/></div>
					<div class="grid2"><span class="bold red hidden" id="emoney_remitter_address_error">Required field.</span></div>
					<div class="clrboth"></div>	
					
					<div class="clrboth"></div>
					<div class="grid2"><span class="bold">*e-Money Order date:</span></div>
					<div class="grid6">
						<div class="datetimeip">
							<input type="text" class="dateip" id="emoney_order_date" name="emoney_order_date" />
						</div>
					</div>
					<div class="grid2"><span class="bold red hidden" id="emoney_order_date_error">Required field.</span></div>
					<div class="clrboth"></div>
				</div>
				 
				<div class="clrboth"></div>
				<div class="grid2"><span class="bold">Attachment:</span></div>
				<div class="grid4"><?php echo form_upload('attachment','','style="margin:5px;"');?></div>
				<div class="clrboth"></div>
				
				<div class="grid2">&nbsp;</div>
				<div class="grid6" style="margin-bottom:50px;"><input type="submit" class="submitclass" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
				<div class="clrboth"></div>	
			 
				<div class="grid2">&nbsp;</div>
				<div class="grid6" id="system_error"></div>
				<div class="clrboth"></div>	
			</div>	
		</div>
	</div>	
	<div class="clrboth"></div>
</div>		
</form>

<script type="text/javascript">
	google.setOnLoadCallback(function() {
		$('#offline_payment').addClass('current');
		$selectedDIV = $('#type').val();
		$('#'+$selectedDIV).removeClass('hidden');
		
		$( "#deposited_date, #transfer_date, #dd_date, #emoney_order_date").datepicker({ 
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd/mm/yy',
			showOn: "button",
			buttonImage: BASE_URI+"addons/default/themes/clicxa/css/images/calendar.png",
			buttonImageOnly: true,
			buttonText: 'Choose date'
		});
		
		var option = { 
			beforeSubmit:  validateBeforeSubmit,  
			success: processAfterSubmit
		};	
		$('#add_coin_offline').ajaxForm(option);
	});
	
	function validateBeforeSubmit(formData, jqForm, options){
		$('#loader_image').show();
		$pack= $('input[name=package]:checked').val();
		if(!isNaturalNumber($pack) ){
			alert("Please select a package firstly.");
			$('#loader_image').hide();
			return false;
		}
		return true;
	}
	
	function processAfterSubmit(responseText, statusText, xhr, $form){
		$('#loader_image').hide();
		var p = new PHP_JS();
		var result_arr = p.explode('#',responseText); 
		if(result_arr[0] == 'msg'){
			$('#system_error').html(result_arr[1]).show();
		}else if(result_arr[0] == 'err'){
			for(i in result_arr){
				$('#'+result_arr[i]).show();
			}
		}else if(result_arr[0] == 'ok'){
			queryURL(BASE_URI+MODULE+'/account/add_coins1_notify');
		}
	}
	
	function changeStateOfSelectedbox(){
		$('#bank_deposit, #neft_transfer, #dd, #emoney_order').addClass('hidden');
		$selectedDIV = $('#type').val();
		$('#'+$selectedDIV).removeClass('hidden');
		
	}
</script>
